<?php

class SecurityUser extends  sfBasicSecurityUser
{
    public function login ($sLogin, $sPassword, $bRemember)
    {
        $oAdmin = AdministratorsQuery::create()
                                    ->filterByUsername( $sLogin )
                                    ->filterByPassword( AdministratorsPeer::hash($sPassword) )
                                    ->findOne();
        
        if(!$oAdmin) return false;
         
        // Запомнить логин и пароль
        $oResponse = sfContext::getInstance()->getResponse();
        
        if( $bRemember )
        {
            $iExpires = time() + 365 * 24 * 3600;
            $oResponse->setCookie( 'username', $sLogin, $iExpires );
            $oResponse->setCookie( 'password', $sPassword, $iExpires );
            $oResponse->setCookie( 'remember', 1, $iExpires );
        }
        else
        {
            $oResponse->setCookie( 'username', '' );
            $oResponse->setCookie( 'password', '' );
            $oResponse->setCookie( 'remember', '' );
        }
        
        $this->setAuthenticated(true);
        
        return $oAdmin;        
    }
    
    public function logout()
    {        
        $this->setAuthenticated(false);
        $this->shutdown();
    }    
}